import { combineReducers, AnyAction } from 'redux';
import * as actionTypes from "./action-types";

const initalState = {
    // 加载中
    loading:true,
    // 排行榜
    ranking:{
        rankingPartitions:[],
        rankingVideos:[]
    },
    // 首页菜单
    partitions:{
        oneLevelPartitions:[]
    }
}


const loadingReducer = (state = initalState.loading,action:AnyAction) => 
{
    switch(action.type) {
        case actionTypes.SET_LOADING:
            return action.data
        default:
            return state
    }
}

const rankingreducer = (state = initalState.ranking,action:AnyAction) => {
    switch(action.type){
        case actionTypes.SET_RANKING_PARTITIONS:
            return {
                ...state,
                rankingPartitions:action.data
            }
        case actionTypes.SET_RANKING_VIDEOS:
            return {
                ...state,
                rankingVideos:action.data
            }
        default:
            return state;
    }
}

const PartitionsReducer = (state = initalState.partitions,action:AnyAction) => {
    switch(action.type) {
        case actionTypes.SET_ONE_LEVEL_PARTITIONS:
            return {
                ...state,
                oneLevelPartitions:action.data
            }
        default:
            return state
    }
}

export default combineReducers({
    loading:loadingReducer,
    ranking:rankingreducer,
    partitions:PartitionsReducer
})